# 杨辉三角
# 打印出杨辉三角

# 杨辉三角 循环嵌套 递推 递归

n = 9

s = []

# 递推
for i in range(n):
    temp = []
    if i == 0:
        temp = [1]
    elif i == 1:
        temp = [1, 1]
    else:
        temp.append(1)
        for j in range(1, i):
            t = s[i-1][j] + s[i-1][j-1]
            temp.append(t)
        temp.append(1)

    s.append(temp)

for i in range(n):
    print(s[i])

# 递归

def trangleYang(n):
    if n == 0:
        s = []
        s.append([1])
        return s
    if n == 1:
        s = trangleYang(n-1)
        s.append([1, 1])
        return s

    temp = []
    s = trangleYang(n-1)

    temp.append(1)
    for i in range(1, n):
        t = s[n-1][i] + s[n-1][i-1]
        temp.append(t)
    temp.append(1)
    s.append(temp)

    return s

s = trangleYang(n-1)
print(*s, sep='\n')

